inline unsigned const char* getTecken() {
	static const unsigned char tecken[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
	return tecken;
}

inline unsigned const char* getReverse() {
	static const unsigned char reverse[] = {
		00,00,00,00, 00,00,00,00, 00,00,00,00, 00,00,00,00,
		00,00,00,00, 00,00,00,00, 00,00,00,00, 00,00,00,00,
		00,00,00,00, 00,00,00,00, 00,00,00,62, 00,00,00,63,
		52,53,54,55, 56,57,58,59, 60,61,00,00, 00,00,00,00,
		00, 0, 1, 2,  3, 4, 5, 6,  7, 8, 9,10, 11,12,13,14,
		15,16,17,18, 19,20,21,22, 23,24,25,00, 00,00,00,00,
		00,26,27,28, 29,30,31,32, 33,34,35,36, 37,38,39,40,
		41,42,43,44, 45,46,47,48, 49,50,51,00, 00,00,00,00,
		00,00,00,00, 00,00,00,00, 00,00,00,00, 00,00,00,00,
		00,00,00,00, 00,00,00,00, 00,00,00,00, 00,00,00,00,
		00,00,00,00, 00,00,00,00, 00,00,00,00, 00,00,00,00,
		00,00,00,00, 00,00,00,00, 00,00,00,00, 00,00,00,00,
		00,00,00,00, 00,00,00,00, 00,00,00,00, 00,00,00,00,
		00,00,00,00, 00,00,00,00, 00,00,00,00, 00,00,00,00,
		00,00,00,00, 00,00,00,00, 00,00,00,00, 00,00,00,00,
		00,00,00,00, 00,00,00,00, 00,00,00,00, 00,00,00,00,
	};
	return reverse;
}

inline char* b64_encode( const char* src, char* result ) {
	unsigned const char* tecken = getTecken();
	const unsigned char* buffer = (const unsigned char*)src;

	int p = 0, i;
	for( i=0; i<510; i+=3 ) {
		result[p++] = tecken[ buffer[i]>>2 ];
		result[p++] = tecken[ ((buffer[i]<<4)&/*0b00110000*/48) | (buffer[i+1]>>4) ];
		result[p++] = tecken[ ((buffer[i+1]<<2)&/*0b00111100*/60) | (buffer[i+2]>>6) ];
		result[p++] = tecken[ buffer[i+2] & /*0b00111111*/63 ];
	}
	
	{
		unsigned char buffer[3] = {(char)src[510], (char)src[511], 0};
		result[p++] = tecken[ buffer[i]>>2 ];
		result[p++] = tecken[ ((buffer[i]<<4)&/*0b00110000*/48) | (buffer[i+1]>>4) ];
		result[p++] = tecken[ ((buffer[i+1]<<2)&/*0b00111100*/60) | (buffer[i+2]>>6) ];
		result[p++] = tecken[ buffer[i+2] & /*0b00111111*/63 ];
	}
	result[p++] = '\0';
}

inline char* b64_decode( const char* src, void* result ) {
	const unsigned char* rev = getReverse();
	unsigned char* res = (unsigned char*)result;
	
	int i, p = 0;
	for( i=0; i<680; i+=4 ) {
		res[p++] = (rev[src[i]]<<2) | (rev[src[i+1]]>>4);
		res[p++] = (rev[src[i+1]]<<4) | (rev[src[i+2]]>>2);
		res[p++] = (rev[src[i+2]]<<6) | rev[src[i+3]];
	}
	res[p++] = (rev[src[i]]<<2) | (rev[src[i+1]]>>4);
	res[p++] = (rev[src[i+1]]<<4) | (rev[src[i+2]]>>2);
	
}